package Operation;

import Book.Book;
import Book.Booklist;

import java.util.Scanner;


public class deletBook implements Ioperation {
    @Override
    public void work(Booklist booklist) {
        System.out.println("删除书籍");
        System.out.println("请输入你要删除的书籍");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int size = booklist.getSizeBook();
        int index=-1;
        for (int i = 0; i < size ; i++) {
            Book book = booklist.getBook(i);
            if (book.getBookName().equals(name)) {
                System.out.println("找到了你要删除的书");
                index=i;
                break;
            }
        }
        if(index==-1){
            System.out.println("没有找到你要的书");
        }
        for (int j = 0; j < size - 1; j++) {
            Book book1 = booklist.getBook(index + 1);
            booklist.setBook(index, book1);
            index++;
        }
        booklist.setSizeBook(size-1);
        System.out.println("删除成功");
    }
}
